﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace ZHDJ.Data.Models.BaseInfo
{
    /// <summary>
    /// 字典
    /// </summary>
    public class DataDictionary : EntityBase
    {
        /// <summary>
        /// 字典类型
        /// </summary>
        [StringLength(64)]
        public string DDicType { get; set; }

        /// <summary>
        /// 字典成员值
        /// </summary>
        [StringLength(64)]
        public string DDicMember { get; set; }


        /// <summary>
        /// 字典成员名称
        /// </summary>
        [StringLength(64)]
        public string DDicMemberName { get; set; }


        /// <summary>
        /// 自定义1
        /// </summary>
        [StringLength(64)]
        public string UDF1 { get; set; }

        /// <summary>
        /// 自定义2
        /// </summary>
        [StringLength(64)]
        public string UDF2 { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int? OrderNo { get; set; }

        #region 数据查询
        /// <summary>
        /// 获所有数据字典类型
        /// </summary>
        /// <returns></returns>
        public static DataSet GetDDicTypeList(int pageIndex = 0, int pageSize = 20)
        {
            var para = new List<MySqlParameter>
            {
              new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "Begin",
                    Value = (pageIndex)*pageSize
                },
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "PageSize",
                    Value = pageSize
                }
            };
            var sql = new StringBuilder(@"SELECT SQL_CALC_FOUND_ROWS DDicType FROM tblDataDictionary group by DDicType
                           ORDER BY DDicType LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return MySqlHelper.ExecuteDataSet(sql.ToString(), para.ToArray());
        }
        #endregion

    }
}
